package com.android.djlmapp.activity.kuandai;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.djlmapp.R;
import com.android.djlmapp.adapter.kuandai.KuanDaiDiQuAdapter;
import com.android.djlmapp.model.kaika.KaiKaHomeInfo;
import com.android.djlmapp.model.kaika.SelectNumInfo;
import com.android.djlmapp.tools.global.ToastUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 宽带选择地区
 */
public class KuanDaiDiQuActivity extends Activity {

    @BindView(R.id.diqu_cancle)
    TextView diquCancle;
    @BindView(R.id.diqu_ok)
    TextView diquOk;
    @BindView(R.id.diqu_recycler)
    RecyclerView diquRecycler;
    @BindView(R.id.rl_progress)
    RelativeLayout rlProgress;
    private List<SelectNumInfo.PhoneList> listNumData = new ArrayList<>();
    private KuanDaiDiQuAdapter kuanDaiDiQuAdapter;
    private String addressQu; // 城市名称
    private String diQuId; // 地区编码
    private String diQuAddress; // 地区
    private List<KaiKaHomeInfo.KdAdressBean.AreaListBean> diQuList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kuan_dai_di_qu);
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        ButterKnife.bind(this);
        initView();
        initData();
    }

    protected void initView() {
        Bundle bundle = getIntent().getExtras();
        addressQu =bundle.getString("AddressQu");
        diQuList = (List<KaiKaHomeInfo.KdAdressBean.AreaListBean>) bundle.getSerializable("DIQULIST");
        kuanDaiDiQuAdapter = new KuanDaiDiQuAdapter(KuanDaiDiQuActivity.this);
        kuanDaiDiQuAdapter.setOnItemClickListener(new KuanDaiDiQuAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(KaiKaHomeInfo.KdAdressBean.AreaListBean item) {
                diQuId = item.getId();
                diQuAddress = item.getName();
                Log.e("宽带地区数据适配器", diQuId + "------onItemClick------" + diQuAddress);
            }
        });
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        diquRecycler.setLayoutManager(linearLayoutManager);

        // 设置Adapter
        diquRecycler.setAdapter(kuanDaiDiQuAdapter);
    }

    protected void initData() {

        if (diQuList != null && diQuList.size() > 0) {
            kuanDaiDiQuAdapter.setList(diQuList);
        } else {
            ToastUtils.showShortToast(KuanDaiDiQuActivity.this, "未获取到地区数据");
        }
    }


    @OnClick({R.id.diqu_cancle, R.id.diqu_ok})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.diqu_cancle:
                finish();
                break;
            case R.id.diqu_ok:
                Intent intent = new Intent();
                intent.putExtra("DIQU", diQuId);
                intent.putExtra("DIQUADDRESS", diQuAddress);
                setResult(RESULT_OK, intent);
                finish();
                overridePendingTransition(R.anim.push_left_in, R.anim.push_right_out);
                break;
        }
    }
}
